Results 1 to 12 of 12

Thread: Couldn't link opencv with qt creator , this error happens

  1. #1
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Couldn't link opencv with qt creator , this error happens

    Hello,

    I've been trying to solve this since yesterday with no luck,

    first I downloaded the latest version of opencv , it came with it two folders , one is source and one is build I assumed build folder is the precompiled folder which is what I want, anyways I did this in the pro file:

    Qt Code:
    1. INCLUDEPATH += C:/opencv/build/include
    2. LIBS +=-LC:/opencv/build/x86/vc11/staticlib
    3. CONFIG(debug, debug|release){
    4. LIBS +=-lopencv_core249\
    5. LIBS +=-lopencv_core249d\
    6. LIBS +=-lopencv_highgui249\
    7. LIBS +=-lopencv_highgui249d\
    8. }
    To copy to clipboard, switch view to plain text mode 

    and it gives me this error:

    Qt Code:
    1. :-1: error: LNK1104: cannot open file '+=-lopencv_core249d.obj'
    To copy to clipboard, switch view to plain text mode 

    when I delete
    LIBS +=-lopencv_core249d\

    it gives me the same error except it's for the highgui249d file.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Couldn't link opencv with qt creator , this error happens

    The -l lib name option needs to be on the same line as the -L so you need a \, and also the debug/release are not supposed to be linked together, so the syntax should become something like:
    Qt Code:
    1. CONFIG( debug, debug|release ) {
    2. #debug libs
    3. LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    4. -lopencv_core246d\
    5. -lopencv_highgui246d
    6. }
    7. else {
    8. #release libs
    9. LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    10. -lopencv_core246\
    11. -lopencv_highgui246
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zlatomir; 2nd May 2014 at 19:42.

  3. The following user says thank you to Zlatomir for this useful post:

    Being friendzoned sucks (2nd May 2014)

  4. #3
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Couldn't link opencv with qt creator , this error happens

    Quote Originally Posted by Zlatomir View Post
    The -l lib name option needs to be on the same line as the -L so you need a \, and also the debug/release are not supposed to be linked together, so the syntax should become something like:
    Qt Code:
    1. CONFIG( debug, debug|release ) {
    2. #debug libs
    3. LIBS += -LLIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    4. -lopencv_core246d\
    5. -lopencv_highgui246d
    6. }
    7. else {
    8. #release libs
    9. LIBS += -LLIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    10. -lopencv_core246\
    11. -lopencv_highgui246
    12. }
    To copy to clipboard, switch view to plain text mode 
    well thanks buddy , now I have a new problem:

    LNK1181: cannot open input file 'opencv_core246.lib'

    when I compile in release mode and when I compile in debug mode it shows the same problem except for the debug file:

    LNK1181: cannot open input file 'opencv_core246d.lib'

  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Couldn't link opencv with qt creator , this error happens

    My bad, sorry, some copy/paste errors, i corrected the error in my previous post, and also you seem to have the 2.49 version of opencv (you can check the file names in that lib folder), so the code becomes:
    Qt Code:
    1. CONFIG( debug, debug|release ) {
    2. #debug libs
    3. LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    4. -lopencv_core249d\
    5. -lopencv_highgui249d
    6. }
    7. else {
    8. #release libs
    9. LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
    10. -lopencv_core249\
    11. -lopencv_highgui249
    12. }
    To copy to clipboard, switch view to plain text mode 

    LE: don't forget to run qmake after you modify the .pro file.

  6. The following user says thank you to Zlatomir for this useful post:

    Being friendzoned sucks (2nd May 2014)

  7. #5
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Couldn't link opencv with qt creator , this error happens

    Yeah I fixed the copy thing before using it

    but I'm stupid enough to forget about changing the names to the new version names..

    anyways they're still some problems

    first I added these to my pro file:

    Qt Code:
    1. INCLUDEPATH += C:/opencv249/build/include/
    2. CONFIG( debug, debug|release ) {
    3. #debug libs
    4. LIBS +=-LC:/opencv249/build/x64/vc11/staticlib\
    5. -lopencv_core249d\
    6. -lopencv_highgui249d
    7. }
    8. else {
    9. #release libs
    10. LIBS +=-LC:/opencv249/build/x64/vc11/staticlib\
    11. -lopencv_core249\
    12. -lopencv_highgui249
    13. }
    To copy to clipboard, switch view to plain text mode 

    second here is the includes + code

    Qt Code:
    1. #include<opencv/cv.h>
    2. #include<opencv/highgui.h>
    3.  
    4. void MainWindow::showimage1(){
    5. IplImage*img=cvLoadImage("C:\\Users\\myuser\\QT\\build-CaptureTools-Unnamed-Debug\\Fri May 2 2014_3039.png");
    6. cvNamedWindow("example",CV_WINDOW_AUTOSIZE);
    7. cvShowImage("example",img);
    8. cvWaitKey(0);
    9. cvReleaseImage(&img);
    10. cvDestroyWindow("example");
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    ------------------------------------------

    first I'll start with the notifications that it shows in the issues section along with the errors:

    Qt Code:
    1. C:\opencv249\build\include\opencv2\flann\logger.h:66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    2.  
    3. C:\opencv249\build\include\opencv2\flann\logger.h:66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    4.  
    5. C:\opencv249\build\include\opencv2\flann\logger.h:66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    To copy to clipboard, switch view to plain text mode 


    -----------------------------------------------------

    the errors:

    Qt Code:
    1. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvReleaseImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    2.  
    3. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvNamedWindow referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    4.  
    5. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvShowImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    6.  
    7. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvDestroyWindow referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    8.  
    9. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvLoadImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    10.  
    11. mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvWaitKey referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)
    12.  
    13. debug\CaptureTools.exe:-1: error: LNK1120: 6 unresolved externals
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Couldn't link opencv with qt creator , this error happens

    Are you trying to build using the same compiler as opencv version? (from the opencv path is seems to be vc11, that means Visual Studio 2012)

  9. The following user says thank you to Zlatomir for this useful post:

    Being friendzoned sucks (2nd May 2014)

  10. #7
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Couldn't link opencv with qt creator , this error happens

    yes I've tried woith many compilers but it didn't work , including msvc 11


    Added after 37 minutes:


    Hello zlatomir are you there ?

    I found this:

    http://stackoverflow.com/questions/1...-visual-studio

    maybe it's similar to my problem but I couldn't understand his solution ?

    I'm using qt 5.1.1 built it statically and using x86 msvc11 , my windows is 64bit if this is important , anyways the problem is still happens.. when I use the x86 libraries like this:
    LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\

    it shows a lot of errors most of them are called " mismatch "
    Last edited by Being friendzoned sucks; 2nd May 2014 at 20:58.

  11. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Couldn't link opencv with qt creator , this error happens

    Use the x86 folder if you built x86 Qt, don't forget to run qmake after you modify the .pro file, and also for static linkage you should add some more libraries:
    Qt Code:
    1. INCLUDEPATH += C:/opencv249/build/include/
    2. CONFIG( debug, debug|release ) {
    3. #debug libs
    4. LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\
    5. -lopencv_core249d\
    6. -lopencv_highgui249d\
    7. -lIlmImfd\
    8. -llibpngd\
    9. -llibjpegd\
    10. -llibjasperd\
    11. -lIlmImfd\
    12. -lzlibd
    13. }
    14. else {
    15. #release libs
    16. LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\
    17. -lopencv_core249\
    18. -lopencv_highgui249\
    19. -lIlmImf\
    20. -llibpng\
    21. -llibjpeg\
    22. -llibjasper\
    23. -lIlmImf\
    24. -lzlib
    25. }
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to Zlatomir for this useful post:

    Being friendzoned sucks (2nd May 2014)

  13. #9
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Couldn't link opencv with qt creator , this error happens

    Thanks , still the same problem if I used the x64 folder , and when I use the x86 it shows me about 180 errors most of them are mismatch , like this error:

    opencv_core249d.lib(array.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj

  14. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Couldn't link opencv with qt creator , this error happens

    Just for testing try to link with dynamic opencv (use the x86 folder and lib instead of staticlib)

  15. The following user says thank you to Zlatomir for this useful post:

    Being friendzoned sucks (2nd May 2014)

  16. #11
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Couldn't link opencv with qt creator , this error happens

    when using both x64 folder and x86 after applying what you've said this error happens:

    Qt5Widgetsd.lib(qapplication.obj):-1: error: LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

    well I think it's working

    thanks man

    but why can't I use the static lib ? does that mean I have to include the files to my exe program ? how can I build it statically ?

  17. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Couldn't link opencv with qt creator , this error happens

    Just for the record the reason for the failure in the first post is the trailing backslashes on line 4 through 7. The line starting at 4 effectively becomes:
    Qt Code:
    1. LIBS +=-lopencv_core249 LIBS +=-lopencv_core249d LIBS +=-lopencv_highgui249 LIBS +=-lopencv_highgui249d }
    To copy to clipboard, switch view to plain text mode 
    Leading the linker to try to look for a file literally called "+=-lopencv_core249d" that does not exist.

Similar Threads

  1. Qt Creator 5.0.1 and OpenCv 2.4.3 mingw x86
    By marcocadei in forum Installation and Deployment
    Replies: 11
    Last Post: 16th February 2013, 20:20
  2. OpenCV integration with Qt creator
    By mind_freak in forum Qt Programming
    Replies: 11
    Last Post: 8th January 2013, 22:50
  3. Qt Creator and OpenCV , .dll missing
    By schludy in forum Newbie
    Replies: 0
    Last Post: 30th November 2011, 10:11
  4. Problem with openCV compilation in Qt Creator
    By mind_freak in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2011, 12:26
  5. Using OpenCV with QT creator
    By gmiller39 in forum Newbie
    Replies: 3
    Last Post: 7th July 2010, 15:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.